package com.ygsoft.example.employee;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class EmployeeController {
	private Logger log = Logger.getLogger(EmployeeController.class);

	@Autowired
	private EmployeesService employeesService;

	public EmployeeController() {
		log.info("-----------------------> Employee Contoller is just initialized ..");
	}

	@RequestMapping("/allEmp.do")
	public ModelAndView printWelcome() {
		log.debug("========> Employee Request Detected ..");
		
		ModelAndView modelAndView = new ModelAndView();
		List<Employees> employeesList = this.employeesService.getEmployeesList();
		int i = 0;
		for (Employees emp : employeesList) {
			log.info(i++ + ":" + emp.getFirstName());
		}

		modelAndView.addObject("message", "Spring 3 MVC Hello World" + System.currentTimeMillis());
		modelAndView.setViewName("welcome");
		return modelAndView;
	}
}
